<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 2014-2015 Luca Agostini, Alessandro Cantini, Alessandro Dignani
  ~
  ~ This file is part of MeteoCal.
  ~
  ~ MeteoCal is free software: you can redistribute it and/or modify
  ~ it under the terms of the GNU General Public License as published by
  ~ the Free Software Foundation, either version 3 of the License, or
  ~ (at your option) any later version.
  ~
  ~ This program is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ~ GNU General Public License for more details.
  ~
  ~ You should have received a copy of the GNU General Public License
  ~ along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:component="http://java.sun.com/jsf/composite/components"
      xmlns:f="http://java.sun.com/jsf/core">

<h:head>
    <title>MeteoCal settings</title>
</h:head>
<h:body>
    <div id="settingsform">
        <component:banner/>

        <p:messages id="messages"/>
        <p:panel header="Confirm your email"
                 rendered="#{not settingsBean.user.hasConfirmedEmail()}">
            <h:form>
                <h:outputText value="Insert the token received via email: "/>
                <p:inputText value="#{settingsBean.token}">
                    <p:ajax update="confirmButton" event="keyup"/>
                </p:inputText>
                <p:commandButton id="confirmButton" value="Confirm"
                                 action="#{settingsBean.confirmEmail}"
                                 disabled="#{settingsBean.token == null}"
                                 icon="ui-icon-check"
                                 ajax="false"/>
                <p:commandButton value="Resend email"
                                 icon="ui-icon-mail-closed"
                                 action="#{settingsBean.reSendEmail}"
                                 update=":messages"/>
            </h:form>
        </p:panel>
        <p:panel header="Import/export calendar">
            <h:form>
                <p:commandButton value="Export Calendar"
                                 icon="ui-icon-arrowstop-1-s"
                                 ajax="false"
                                 id="exportCalendar">
                    <p:fileDownload value="#{settingsBean.exportCalendar()}"/>
                </p:commandButton>
            </h:form>

            <h:form enctype="multipart/form-data">
                <p:commandButton value="Import Calendar"
                                 icon="ui-icon-arrowstop-1-n"
                                 ajax="false"
                                 id="importCalendar"
                                 actionListener="#{settingsBean.importCalendar}"
                                 disabled="false"/>
                <p:fileUpload value="#{settingsBean.importFile}"
                              uploadLabel="Import File"
                              mode="simple"
                              update="importCalendar"/>
            </h:form>
        </p:panel>
        <p:panel header="General settings">
            <h:form>
                <p:panelGrid columns="2">
                    <p:outputLabel value="Public calendar: " id="publicCalendar"/>
                    <p:inputSwitch value="#{settingsBean.user.calendar.public}"
                                   onLabel="Yes" offLabel="No"/>

                    <p:outputLabel value="Email receiving: " id="receveingMail"/>
                    <p:inputSwitch value="#{settingsBean.user.receivingEmail}"
                                   onLabel="Yes" offLabel="No"
                                   disabled="#{not settingsBean.user.hasConfirmedEmail()}"/>

                    <p:outputLabel value="Timezone: "/>
                    <h:selectOneMenu value="#{settingsBean.user.calendar.timeZone}">
                        <f:selectItems value="#{settingsBean.availableTimeZones}"/>
                    </h:selectOneMenu>

                    <p:outputLabel value="Temperature unit: "/>
                    <h:selectOneMenu id="tempUnit" value="#{settingsBean.user.temperatureUnit}">
                        <f:selectItems value="#{settingsBean.availableTemperatureUnits}" var="t"
                                       itemLabel="#{t.name}"/>
                    </h:selectOneMenu>

                    <p:outputLabel value="Date format: "/>
                    <h:selectOneMenu id="dateFormat" value="#{settingsBean.user.datePattern}">
                        <f:selectItems value="#{settingsBean.availableDatePatterns}" var="dp"
                                       itemLabel="#{dp.example}"/>
                    </h:selectOneMenu>

                    <p:outputLabel value="Time format: "/>
                    <h:selectOneMenu id="timeFormat" value="#{settingsBean.user.timePattern}">
                        <f:selectItems value="#{settingsBean.availableTimePatters}" var="tp"
                                       itemLabel="#{tp.example}"/>
                    </h:selectOneMenu>
                </p:panelGrid>
                <p:tooltip for="publicCalendar" showEffect="clip"
                           value="Makes your calendar public. If you make your calendar public the
                            other users may see the time slots in which you are busy, without seeing the details,
                            unless you have set your events as public."/>
                <p:tooltip for="receveingMail" showEffect="clip"
                           value="Set it to yes if you want to receive email notifications. To start
                           receveing email notifications you must confirm your email first."/>

                <p:separator/>

                <p:commandButton value="Save" action="#{settingsBean.saveAction}"
                                 icon="ui-icon-disk"/>
                <p:button value="Home" icon="ui-icon-home" outcome="/user/home"/>
            </h:form>
        </p:panel>
    </div>


</h:body>
</html>
